if not CLIENT then return false end -- Clientside only :)

--[[
made by:
 ____ _______                    _
|  __|__   __|_  _ __   ____  __| |
 \ \    | |/ _ \| '_ \ / __ )/ _` |
 _\ \   | | (_) | | | | (__ | (_| |
|____|  |_|\___/|_| |_|\__,_)\__,_|

]]

Spin = {}
Spin.Version = 2.1

local seteyeang = seteyeang or _R.Player.SetEyeAngles
local spinhack = false
local key = false
local resorig = false
local resspin = false
local spinspeed = CreateClientConVar("spin_speed",1,true,false)
local speed = 0
local view = Angle(0,0,0)
local fakeview = Angle(0,0,0)

function Spin.FakeView(user)
	if (spinhack == true and key ~= true) then
		local sensitivity =  0.022
		fakeview.p = fakeview.p + (user:GetMouseY() * sensitivity)
		fakeview.p = math.Clamp(fakeview.p, -90, 90)
		view.y = view.y + (user:GetMouseX() * sensitivity * -1)
		local move = Vector(user:GetForwardMove(), user:GetSideMove(), 0)
		speed = math.Clamp(spinspeed:GetFloat(),1,10)
		speed = speed * 35.9
		local spinang = Angle(0,LocalPlayer():EyeAngles().y + speed,0)
		user:SetViewAngles(spinang)
		local set = (move:Angle() + (spinang - view)):Forward() * move:Length()
		user:SetForwardMove(set.x)
		user:SetSideMove(set.y)
	end
end
hook.Add("CreateMove", "FakeView", Spin.FakeView)

function Spin.ResetView(bool)
	if (resorig and bool == 1) then
		seteyeang(LocalPlayer(),Angle(fakeview.p,view.y,0))
		resorig = false
	elseif (resspin and bool == 2) then
		fakeview.p = LocalPlayer():EyeAngles().p
		view.y = LocalPlayer():EyeAngles().y	
		resspin = false
	end
end

function Spin.Toggle()
	if (spinhack == false) then
	    view = LocalPlayer():EyeAngles()
	    fakeview = LocalPlayer():EyeAngles()
		spinhack = true
	else
	    spinhack = false
	    resorig = true
		Spin.ResetView(1)
	end
end
concommand.Add("spinhack",Spin.Toggle)

function Spin.Calc( ply, origin, angles, fov )
	if (spinhack == true and key ~= true) then
		local cview = {}
		cview.origin = origin + Vector(0,0,0)
		cview.angles = Angle(fakeview.p,view.y,0)
		return cview
 	else
		return origin, angles, fov
	end
end
hook.Add("CalcView", "SpinCalc", Spin.Calc)

function Spin.Think()
	if (spinhack) then
	if (LocalPlayer():KeyDown(IN_ATTACK) or LocalPlayer():KeyDown(IN_USE)) then
		key = true
		resspin = true
		Spin.ResetView(1)
	else
		key = false
		resorig = true
		Spin.ResetView(2)
	end
	end
end
hook.Add("Think","Press E / Mouse1 to disable ( Ladder )",Spin.Think)